<template>
	<div>
		<el-row :gutter="24">
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">时间:</p>
			</el-col>
			<el-col :span="4">
				<el-date-picker size="small" style="width: 95%;" v-model="conditions.date" format="yyyy-MM" :editable=false type="month" placeholder="时间">
				</el-date-picker>
			</el-col>
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">保单类别:</p>
			</el-col>
			<el-col :span="4">
				<el-select size="small" style="width: 100%;" v-model="conditions.iscompulsoryinsurance" placeholder="请选择保险类别" clearable>
					<el-option v-for="item in insuranceCombo" :label="item.label" :value="item.value"></el-option>
				</el-select>
			</el-col>
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">保险小类:</p>
			</el-col>
			<el-col :span="4">
				<el-select size="small" style="width: 100%;" v-model="conditions.insureType" placeholder="请选择保险类别" clearable>
					<el-option label="新保" value="sb"></el-option>
					<el-option label="续保" value="xb"></el-option>
				</el-select>
			</el-col>
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">佣金类别:</p>
			</el-col>
			<el-col :span="4">
				<el-select size="small" style="width: 100%;" v-model="conditions.commissionType" placeholder="请选择佣金类别" clearable>
					<el-option v-for="item in commissionCombo" :label="item.label" :value="item.value"></el-option>
				</el-select>
			</el-col>
		</el-row>
		<el-row :gutter="24">
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">区域:</p>
			</el-col>
			<el-col :span="4">
				<el-select size="small" v-model="conditions.oArea" @change="getCompanyInfo" style="width: 100%;" placeholder="请选择区域" clearable>
					<el-option v-for="item in areaCombo" :label="item.label" :value="item.value"></el-option>
				</el-select>
			</el-col>
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">应用单位:</p>
			</el-col>
			<el-col :span="4">
				<el-select size="small" style="width: 100%;" v-model="conditions.applyUnitId" placeholder="请选择公司名称" clearable>
					<el-option v-for="item in creatcompanyCombo" :label="item.oName" :value="item.id"></el-option>
				</el-select>
			</el-col>
			<el-col :span="1" style="margin-right: 10px;">
				<p class="queryLabel">保险公司:</p>
			</el-col>
			<el-col :span="4">
				<el-select size="small" style="width: 100%;" v-model="conditions.companyId" placeholder="请选择保险公司" clearable>
					<el-option v-for="item in companyCombo" :label="item.insuranceCompanyName" :value="item.id"></el-option>
				</el-select>
			</el-col>
			
			<el-col :span="2" style="text-align: center">
				<el-button type="primary" size="small" v-on:click='commissionQuery'>查询</el-button>
			</el-col>
			<el-col :span="7" style="margin-left: -30px;text-align: right">
				<el-button type="primary" size="small" v-on:click='addCommission'>新增</el-button>
				<el-button type="primary" size="small" v-on:click='editComs'>编辑</el-button>
			</el-col>
		</el-row>
		<el-row>
			<el-col :span="24">
				<el-table :data="tableDatas.dataList" border style="width: 100%;align-content: center;" @selection-change="handleSelectionChanges" :row-class-name="tableRowClassName">
					<el-table-column type="selection" width="60">
					</el-table-column>
					<el-table-column label="保险公司" prop="insuranceCompanyCode">
					</el-table-column>
					<el-table-column label="保险类别" prop="insuranceType" :formatter="insCov">
					</el-table-column>
					<el-table-column label="保单类别" prop="iscompulsoryinsurance">
					</el-table-column>
					<el-table-column label="投保类别" prop="insureType" :formatter="insureCov">
					</el-table-column>
					<el-table-column label="佣金类别" align="right" prop="commissionType" :formatter="commCov">
					</el-table-column>
					<el-table-column label="起始日期" align="right" prop="startDate">
					</el-table-column>
					<el-table-column label="终止日期" align="right" prop="stopDate">
					</el-table-column>
					<el-table-column label="佣金" align="right" prop="commission">
					</el-table-column>
					<el-table-column label="应用单位" align="right" prop="oName" :formatter="applyUnitCov" width="250">
					</el-table-column>
					<el-table-column label="佣金状态" align="right" prop="status" :formatter="sCov">
					</el-table-column>
					<!--<el-table-column label="操作" align="right" prop="">
							</el-table-column>-->
				</el-table>
				<el-pagination small @size-change="handleSizeChange" @current-change="handleCurrentChanges" :current-page="CurentPages" :page-sizes="page.pageSizes" :page-size="page.pageSize" layout=" total,prev, pager, next" :total="tableDatas.total">
				</el-pagination>
			</el-col>
		</el-row>
		<el-dialog title="佣金维护" v-model="comFormShows" size="small">
			<el-form :model="comFormDatas.insurance" ref="comForms" :rules="yongjinRule" label-width="150px">
				<!--:rules="yongjinRule"-->
				<el-row :gutter="24">
					<el-col :span="12">
						<el-form-item label="保险类别：" required>
							<el-select size="small" style="width: 100%;" @change="insuranceTypeChange" v-model="hehe" placeholder="请选择保险类别" clearable>
								<el-option v-for="item in insuranceCombo" :label="item.label" :value="item.value"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="投保类别：" prop="insureType">
							<el-select size="small" style="width: 100%;" v-model="comFormDatas.insurance.insureType" placeholder="请选择保险类别" clearable>
								<el-option label="新保" value="sb"></el-option>
								<el-option label="续保" value="xb"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="佣金类别：" prop="commissionType">
							<el-select size="small" style="width: 100%;" v-model="comFormDatas.insurance.commissionType" placeholder="请选择佣金类别" clearable>
								<el-option v-for="item in commissionCombo" :label="item.label" :value="item.value"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12" v-if="jqShow">
						<el-form-item label="交强险佣金(%)：" prop="jqCommission">
							<el-input type="number" style="width: 95%;" v-model="comFormDatas.insurance.jqCommission"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" v-if="jqShow">
						<el-form-item label="车船税佣金(%)：" prop="ccsCommission">
							<el-input type="number" style="width: 95%;" v-model="comFormDatas.insurance.ccsCommission"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12" v-if="syShow">
						<el-form-item label="商业险佣金(%)：" prop="syCommission">
							<el-input type="number" style="width: 95%;" v-model="comFormDatas.insurance.syCommission"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="起始日期：" prop="startDate">
							<el-date-picker size="small" style="width:95%" v-model="comFormDatas.insurance.startDate" format="yyyy-MM-dd" :editable=false type="date" placeholder="开始日期" @change="setStopValue">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="终止日期：" prop="stopDate">
							<el-date-picker size="small" style="width:95%" v-model="comFormDatas.insurance.stopDate" format="yyyy-MM-dd" :editable=false type="date" placeholder="终止日期">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="选择区域：" required>
							<el-select size="small" v-model="comFormDatas.insurance.area" style="width: 100%;" @change="companydata" placeholder="请选择区域" clearable>
								<el-option v-for="item in areaCombo" :label="item.label" :value="item.value"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="应用单位：" prop="applyUnit">
							<el-select size="small" style="width: 100%;" v-model="comFormDatas.carCompany" placeholder="请选择应用单位" clearable :multiple="isMultiple">
								<el-option v-for="item in applyUnitCombo" :label="item.oName" :value="item.id"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="佣金说明：" prop="remark">
							<el-input type="textarea" style="width: 95%;" :maxlength="200" v-model="comFormDatas.insurance.remark" :autosize="{ minRows: 2, maxRows: 4}" size="small">
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="comFormShows = false">取 消</el-button>
				<el-button type="primary" v-on:click='saveCommission'>提 交</el-button>
			</div>
		</el-dialog>
		<el-dialog title="编辑费率信息" v-model="editCommissionShow" size="small">
			<el-form :model="editFormData" ref="editForms" :rules="editRule" label-width="150px">
				<!--:rules="yongjinRule"-->
				<el-row :gutter="24">
					<el-col :span="12">
						<el-form-item label="保险类别：">
							<el-select size="small" disabled style="width: 100%;" v-model="editFormData.iscompulsoryinsurance" placeholder="请选择保险类别" clearable>
								<el-option v-for="item in insuranceCombo" :label="item.label" :value="item.value"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="投保类别：" prop="insureType">
							<el-select size="small" style="width: 100%;" v-model="editFormData.insureType" placeholder="请选择保险类别" clearable>
								<el-option label="新保" value="sb"></el-option>
								<el-option label="续保" value="xb"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="佣金类别：" prop="commissionType">
							<el-select size="small" style="width: 100%;" v-model="editFormData.commissionType" placeholder="请选择佣金类别" clearable>
								<el-option v-for="item in commissionCombo" :label="item.label" :value="item.value"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="佣金(%)：" prop="commission">
							<el-input type="number" style="width: 95%;" v-model="editFormData.commission"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="起始日期：" prop="startDate">
							<el-date-picker size="small" style="width:95%" v-model="editFormData.startDate" format="yyyy-MM-dd" :editable=false type="date" placeholder="开始日期" @change="setStopValue">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="终止日期：" prop="stopDate">
							<el-date-picker size="small" style="width:95%" v-model="editFormData.stopDate" format="yyyy-MM-dd" :editable=false type="date" placeholder="终止日期">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="选择区域：">
							<el-select size="small" disabled v-model="editFormData.area" style="width: 100%;" @change="companydata" placeholder="请选择区域" clearable>
								<el-option v-for="item in areaCombo" :label="item.label" :value="item.value"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="应用单位：">
							<el-input style="width: 95%;" readonly :maxlength="200" v-model="editFormData.applyUnitName" :autosize="{ minRows: 2, maxRows: 4}" size="small">
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="佣金说明：" prop="remark">
							<el-input type="textarea" style="width: 95%;" :maxlength="200" v-model="editFormData.remark" :autosize="{ minRows: 2, maxRows: 4}" size="small">
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="editCommissionShow = false">取 消</el-button>
				<el-button type="primary" v-on:click='saveEditCommission'>提 交</el-button>
			</div>
		</el-dialog>
		<el-dialog title="审核" v-model="auditShow" size="mini">
			<div>
				<strong style="font-size: 16px;">佣金说明：</strong>
				<br><br>
				<strong style="font-size: 13px;">{{message}}</strong>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button type="danger" v-on:click='auditing(0)'>审核不通过</el-button>
				<el-button type="primary" v-on:click='auditing(1)'>审核通过</el-button>
			</div>
		</el-dialog>
	</div>
</template>
<script>
	import moment from 'moment'
	export default {
		data: function() {

			return {
				creatcompanyCombo:[],//应用单位
				//编辑费率界面显示
				editCommissionShow: false,
				//编辑时不可修改
				addoredit: false,
				hehe: "", //保险类型
				//交强险佣金显示
				jqShow: false,
				//商业险佣金显示
				syShow: false,
				//编辑校验规则
				editRule: {
					remark: [{
						required: true,
						message: '请输入佣金说明',
						trigger: 'blur'
					}],
					insureType: [{
						required: true,
						message: '请选择',
						trigger: 'blur'
					}],
					commissionType: [{
						required: true,
						message: '请选择',
						trigger: 'blur'
					}],
					commission: [{
						required: true,
						message: '请选择',
						trigger: 'blur'
					}],
					startDate: [{
						type: 'date',
						required: true,
						message: '请选择',
						trigger: 'blur'
					}],
					stopDate: [{
						type: 'date',
						required: true,
						message: '请选择',
						trigger: 'blur'
					}],
				},
				//校验规则
				yongjinRule: {
					remark: [{
						required: true,
						message: '请输入佣金说明',
						trigger: 'blur'
					}],
					area: [{
						required: true,
						message: '请选择区域',
						trigger: 'blur'
					}],
					//					iscompulsoryinsurance: [{
					//						required: true,
					//						message: '请选择保险类别',
					//						trigger: 'blur'
					//					}],
					insureType: [{
						required: true,
						message: '请选择投保类别',
						trigger: 'blur'
					}],
					commissionType: [{
						required: true,
						message: '请选择佣金类别',
						trigger: 'blur'
					}],
					syCommission: [{
						required: true,
						message: '请填写佣金',
						trigger: 'blur'
					}],
					ccsCommission: [{
						required: true,
						message: '请填写佣金',
						trigger: 'blur'
					}],
					jqCommission: [{
						required: true,
						message: '请填写佣金',
						trigger: 'blur'
					}],
					startDate: [{
						type: 'date',
						required: true,
						message: '请选择起始日期',
						trigger: 'blur'
					}],
					stopDate: [{
						type: 'date',
						required: true,
						message: '请选择终止日期',
						trigger: 'blur'
					}],
					//					applyUnit: [{
					//						required: true,
					//						message: '请选择应用单位',
					//						trigger: 'blur'
					//					}],
				},
				message: "",
				auditShow: false,
				isMultiple: true,
				insuranceCombo: [{
					label: '单交强',
					value: '0'
				}, {
					label: '单商业',
					value: '1'
				}, {
					label: '交商共保',
					value: '2'
				}],
				commissionCombo: [{
					label: '常规佣金',
					value: '0'
				}, {
					label: '促销佣金',
					value: '1'
				}],
				//应用单位
				applyUnitCombo: [],
				companyCombo: [],
				//页码数
				CurentPage: 1,
				CurentPages: 1,
				//每页的数量
				page: this.page,
				pages: this.page,
				//公司数据
				tableData: {
					total: 0,
					dataList: []
				},
				//佣金数据
				//分组数据
				tableDatas: {
					total: 0,
					dataList: []
				},
				activeName: 'first',
				companyName: '',
				condition: {
					insuranceCompanyName: ""
				},
				conditions: {
					date: "",
					//公司
					applyUnitId: '',
					//保险公司
					companyId: "",
					//保险类别
					iscompulsoryinsurance: '',
					//投保类别
					insureType: '',
					//佣金类别
					commissionType: '',
					//区域
					oArea: ''
				},
				Emptyconditions: {
					date: "",
					companyId: "",
					//保险类别
					insuranceType: '',
					//投保类别
					insureType: '',
					//佣金类别
					commissionType: '',
					//区域
					oArea: ''
				},
				comFormShows: false,
				comFormDatas: {
					insurance: {
						status: '1',
						remark: '',
						area: "",
						companyId: "",
						createTime: "",
						updateUser: "",
						//投保类别
						iscompulsoryinsurance: '',
						insureType: '',
						createUser: "",
						update: "",
						commission: 1,
						id: "",
						insuranceType: "",
						commissionType: "",
						startDate: "",
						stopDate: "",
						insuranceCompanyName: "",
						jqCommission:"",
						syCommission:"",
						ccsCommission:"",
					},
					//应用单位
					carCompany: [],
				},
				editFormData: {
					iscompulsoryinsurance: '', //保单类别
					insureType: '', //保险类别
					commissionType: '', //佣金类别
					commission: '', //佣金
					startDate: '', //开始时间
					stopDate: '', //结束时间
					area: '', //区域 
					applyUnitName: '', //应用单位
					remark: '', //备注
				},
				editFormDataEmpty: {
					iscompulsoryinsurance: '', //保单类别
					insureType: '', //保险类别
					commissionType: '', //佣金类别
					commission: '', //佣金
					startDate: '', //开始时间
					stopDate: '', //结束时间
					area: '', //区域 
					applyUnitName: '', //应用单位
					remark: '', //备注
				},
				emptyDatas: {
					insurance: {
						status: '1',
						area: "",
						companyId: "",
						createTime: "",
						updateUser: "",
						//投保类别
						insureType: '',
						createUser: "",
						update: "",
						commission: 1,
						id: "",
						insuranceType: "",
						commissionType: "",
						startDate: "",
						stopDate: "",
						insuranceCompanyName: ""
					},
					//应用单位
					carCompany: [],
				},
				multipleSelection: [],
				multipleSelections: [],
				//区域下拉
				areaCombo: [],
				companyId: "",
				all: {
					0: "0_全部"
				}
			}
		},
		methods: {
			//佣金类型转换时触发的方法】
			insuranceTypeChange: function() {
				debugger;
				switch(this.$data.hehe) {
					case '0': //单交强
						this.$data.jqShow = true;
						this.$data.syShow = false;
						break;
					case '1': //单商业
						this.$data.syShow = true;
						this.$data.jqShow = false;
						break;
					case '2': //交商共保
						this.$data.jqShow = true;
						this.$data.syShow = true;
				};
			},
			audit: function() {
				debugger;
				if(this.$data.multipleSelections.length == 0) {
					this.$message.error("请选择数据");
				} else {
					this.$data.auditShow = true;
				}
			},
			//超出预警，标红
			tableRowClassName: function(row, index) {
				debugger;
				if(row.status == 0) {
					return 'positive-row';
				}
			},
			//yongjinzhuangtai
			sCov: function(row, column) {
				if(row.status == '0') {
					return '未审核'
				}
				if(row.status == '1') {
					return '审核通过'
				}
			},
			//状态转换
			insCov: function(row, column) {
				return row.insuranceType == "1" ? '商业险' : '交强险';
			},
			//状态转换
			commCov: function(row, column) {
				return row.commissionType == "1" ? '促销佣金' : '常规佣金';
			},
			//
			insureCov: function(row, column) {
				if(row.insureType == 'sb') {
					return '新保'
				} else {
					return '续保'
				}
			},
			//应用单位转换
			applyUnitCov: function(row, column) {
				//				console.error(JSON.stringify(row))
				if(row.applyUnit == '0') {
					return '全部'
				} else {
					return row.oName
				}
			},
			//选择框
			handleSelectionChanges: function(val) {
				debugger;
				this.$data.multipleSelections = val;
				if(this.$data.multipleSelections.length > 1) {
					this.$message.error("请选择一条数据");
				} else if(this.$data.multipleSelections.length == 1) {
					this.$data.message = this.$data.multipleSelections[0].remark;
				}
			},
			//shenhe
			auditing: function(type) {
				debugger;

				this.$http.post(this.API_ROOT + '/insurance/commission/confim', this.$data.multipleSelections, {
					params: {
						type: type,
					}
				}).then(resp => {
					if(resp.data.success) {
						debugger;
						this.commissionQuery();
						this.$message(resp.data.msg);

					} else {
						this.$message.error(resp.data.msg);
					}
					this.$data.auditShow = false;
				}, resp => {});
			},
			//新增
			addCommission: function() {
				debugger;
				this.$data.hehe = '';
				this.$data.comFormDatas.carCompany = "";
				this.$data.comFormDatas.carCompany = [];
				this.$data.applyUnitCombo = [];
				var emptyDatas = {
					insurance: {
						remark: "",
						area: "",
						companyId: "",
						createTime: "",
						updateUser: "",
						//投保类别
						insureType: '',
						createUser: "",
						update: "",
						commission: "",
						id: "",
						insuranceType: "",
						commissionType: "",
						startDate: "",
						stopDate: "",
						insuranceCompanyName: "",
						jqCommission:"",
						syCommission:"",
						ccsCommission:"",
					},
					//应用单位
					carCompany: [],
				};
				this.$data.comFormDatas = Object.assign(this.$data.comFormDatas, emptyDatas);
				this.$data.comFormDatas.insurance.companyId = this.$data.conditions.companyId;
				this.$data.comFormShows = true;
				this.$data.isMultiple = true;

			},
			//编辑佣金
			editComs: function() {
				if(this.$data.multipleSelections.length == 1) {
					this.$data.isMultiple = false;
					var resRoleData = this.$data.multipleSelections[0];
					this.$http.get(this.API_ROOT + '/insurance/commission/info', {
						params: {
							id: resRoleData.id
						}
					}).then((response) => {
						debugger;
						this.$data.editFormData = Object.assign(this.$data.comFormDatas.insurance, response.data.data);
						this.$data.editFormData.startDate = new Date(this.$data.editFormData.startDate);
						this.$data.editFormData.stopDate = new Date(this.$data.editFormData.stopDate);
					}, (response) => {
						// error callback
					});
					this.$data.editCommissionShow = true; //编辑费率界面显示

				} else {
					this.$message.error("请选择一条数据");
				}
			},
			//查询佣金
			commissionQuery: function() {
				if(this.$data.conditions.date == '' || this.$data.conditions.date == null || this.$data.conditions.date == undefined) {
					this.$data.conditions.date = ''
				} else {
					this.$data.conditions.date = this.moment(this.$data.conditions.date).format("YYYY-MM");
				}
				this.$http.post(this.API_ROOT + '/insurance/commission/page/new', this.$data.conditions, {
					params: {
						start: this.$data.CurentPages,
						limit: this.page.pageSize
					}
				}).then(resp => {
					debugger;
					if(resp.data.success) {
						resp.data.total = parseInt(resp.data.total);
						// es5写法
						this.$data.tableDatas = resp.data;
						//this.baseQuery(this.$data.curTreeDeptId);
						//this.$data.exFormShow = false;
					} else {
						//debugger;
						this.$message.error(resp.data.msg);
					}
				}, resp => {});
			},
			//佣金保存
			saveCommission: function() {
				debugger;
				if(this.$data.hehe == "") {
					this.$message.error("请选择保险类型");
				} else if(this.$data.comFormDatas.carCompany.length == 0) {
					this.$message.error("请选择应用单位");
				} else {
					this.$data.comFormDatas.insurance.jqCommission = Number(this.$data.comFormDatas.insurance.jqCommission).toFixed(2);
					this.$data.comFormDatas.insurance.syCommission = Number(this.$data.comFormDatas.insurance.syCommission).toFixed(2);
					this.$data.comFormDatas.insurance.ccsCommission = Number(this.$data.comFormDatas.insurance.ccsCommission).toFixed(2);
					this.$data.comFormDatas.insurance.iscompulsoryinsurance = this.$data.hehe;
					this.$refs.comForms.validate(function(valid, $event) {
						// 验证通过
						if(valid) {
							debugger;
							this.$data.comFormDatas.insurance.startDate = this.moment(this.$data.comFormDatas.insurance.startDate).format("YYYY-MM-DD");
							this.$data.comFormDatas.insurance.stopDate = this.moment(this.$data.comFormDatas.insurance.stopDate).format("YYYY-MM-DD");
							this.$http.post(this.API_ROOT + '/insurance/commission/save/new', this.$data.comFormDatas)
								.then(resp => {
									if(resp.data.success) {
										this.$message(resp.data.msg);
										debugger;
										//												this.auditing(1);
										this.commissionQuery();
										//												this.commissionQuery();
										this.$data.comFormShows = false;
										this.$data.editCommissionShow = false; //编辑佣金界面
									} else {
										this.$message.error(resp.data.msg);
									}
								}, resp => {});
						} else {
							return false
						}
					}.bind(this))
				}

			},
			//佣金保存
			saveEditCommission: function() {
				debugger;
				this.$refs.editForms.validate(function(valid, $event) {
					// 验证通过
					if(valid) {
						debugger;
						this.$data.editFormData.startDate = this.moment(this.$data.editFormData.startDate).format("YYYY-MM-DD");
						this.$data.editFormData.stopDate = this.moment(this.$data.editFormData.stopDate).format("YYYY-MM-DD");
						this.$http.post(this.API_ROOT + '/insurance/commission/update', this.$data.editFormData)
							.then(resp => {
								if(resp.data.success) {
									this.$message(resp.data.msg);
									debugger;
									this.commissionQuery();
									this.$data.editCommissionShow = false; //编辑佣金界面
								} else {
									this.$message.error(resp.data.msg);
									this.$data.editFormData.startDate = new Date(this.$data.editFormData.startDate);
									this.$data.editFormData.stopDate = new Date(this.$data.editFormData.stopDate);
								}
							}, resp => {});
					}
				}.bind(this))
			},
			//获取应用单位
			companydata: function() {
				debugger;
				this.$http.get(this.API_ROOT + '/insurance/commission/carCompanys', {
					params: {
						area: this.$data.comFormDatas.insurance.area,
					}
				}).then(resp => {
					if(resp.data.success) {
						debugger;
						this.$data.applyUnitCombo = resp.data.data;
						//						console.log(JSON.stringify(resp.data.data))
					} else {
						if(this.$data.comFormDatas.insurance.insureType) {
							this.$message.error(resp.data.msg);
						}

					}
				}, resp => {});
			},
			//获取应用单位
			companydatas: function() {
				debugger;
				this.$http.get(this.API_ROOT + '/insurance/commission/carCompanys', {
					params: {
						area: this.$data.comFormDatas.insurance.area,
					}
				}).then(resp => {
					if(resp.data.success) {
						debugger;
						this.$data.applyUnitCombo = resp.data.data;
						//						console.log(JSON.stringify(resp.data.data))
					} else {

					}
				}, resp => {});
			},
			//设置结束日期的默认值
			setStopValue: function(val) {
				//				console.error(val);
				//				this.$data.comFormDatas.insurance.stopDate = moment(val).add(1, 'months').add(-1,'day');
				//结束日期为当月最后一天
				debugger;
				var time = new Date(this.$data.comFormDatas.insurance.startDate);
				var year = time.getFullYear();
				var month = time.getMonth() + 1;
				if(month > 11) {
					month -= 12; //月份减     
					year++; //年份增 
				};
				var newDate = new Date(year, month, 1);
				var date1 = newDate.getTime();
				var date2 = newDate.getTime() - 1000 * 60 * 60 * 24;
				var date3 = new Date(newDate.getTime() - 1000 * 60 * 60 * 24);
				this.$data.comFormDatas.insurance.stopDate = date3;
			},
			//列表，分页大小切换
			handleSizeChange: function() {},
			handleCurrentChanges: function(currentPage) {
				debugger;
				this.$data.CurentPages = currentPage;
				//this.$data.dictGroup = '';
				this.commissionQuery();
			},
			companyUpdata: function() {
				//获取保险公司下拉
				this.$http.get(this.API_ROOT + '/insurance/companys', {
					params: {}
				}).then((response) => {
					debugger;
					this.$data.companyCombo = response.data.data;
				}, (response) => {});
			},
			//获取公司信息
			getCompanyInfo: function() {
				//this.$data.data.companyId = ""; //清空单位
				this.$data.conditions.applyUnitId = ""; //清空单位
				this.$data.creatcompanyCombo = [];
				debugger;
				this.$http.get(this.API_ROOT + "/rbac/dept/all", {
					params: {
						area: this.$data.conditions.oArea,
					}
				}).then(resp => {
					this.$data.creatcompanyCombo = resp.data.dataList;
					if(this.$data.creatcompanyCombo.length > 0) {
						this.$data.conditions.applyUnitId = this.$data.creatcompanyCombo[0].id;
					}
				});
			},
		},
		//表单创建时执行
		created: function() {
			this.commissionQuery();
			this.getCompanyInfo();
			//获取区域下拉
			this.$http.get(this.API_ROOT + '/insurance/dict/area/combo', {
				params: {}
			}).then((response) => {
				debugger;
				this.$data.areaCombo = response.data;
			}, (response) => {});
			//获取保险公司下拉
			this.$http.get(this.API_ROOT + '/insurance/companys', {
				params: {}
			}).then((response) => {
				debugger;
				this.$data.companyCombo = response.data.data;
			}, (response) => {});
		}

	}
</script>
<style>
	.el-table .info-row {
		height: 10px !important;
	}
	
	.item {
		width: 30px;
	}
	
	.el-form-item {
		clear: both;
	}
	
	.el-dropdown .el-button-group,
	.el-table .el-tooltip,
	.el-table .el-tooltip__rel {
		display: inline;
	}
	
	.el-table {
		height: 100%;
		width: 100%;
	}
	
	#el-select {
		width: 200px;
	}
	
	.el-table .positive-row {
		background: #fb8e7c;
	}
</style>